package com.uphone.magicleafteacher.pro.adapter;

import android.widget.ImageView;
import android.widget.LinearLayout;

import com.blankj.utilcode.util.ScreenUtils;
import com.blankj.utilcode.util.SizeUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.radish.framelibrary.view.glide.GlideUtils;
import com.uphone.magicleafteacher.R;
import com.uphone.magicleafteacher.util.CommonUtil;
import com.uphone.magicleafteacher.view.MyBaseViewHolder;
import com.uphone.magicleafteacher.vo.AudioGuideBean;

public class ListenerTrainListAdapter extends BaseQuickAdapter<AudioGuideBean.AudioWorkListBean, MyBaseViewHolder> {

    private final int mImageWidth;
    private final LinearLayout.LayoutParams mImageParams;
    private final int margin = 10;

    public ListenerTrainListAdapter() {
        super(R.layout.item_listener_train_list);
        mImageWidth = (ScreenUtils.getScreenWidth() - SizeUtils.dp2px(120)) / 7 - margin;
        mImageParams = new LinearLayout.LayoutParams(mImageWidth, mImageWidth);
        mImageParams.rightMargin = margin;
    }

    @Override
    protected void convert(MyBaseViewHolder helper, AudioGuideBean.AudioWorkListBean item) {
        int personNum = item.getFinishStudents() == null ? 0 : item.getFinishStudents().size();
        helper.setText(R.id.tv_num, personNum + "人已完成")
                .setText(R.id.tv_title, CommonUtil.getStr(item.getWorkBookName()));
        LinearLayout imagesLL = helper.getView(R.id.ll_images);
        imagesLL.removeAllViews();
        for (int i = 0; i < personNum; i++) {
            if (i > 6) {
                helper.setText(R.id.tv_num, "..." + personNum + "人已完成");
                break;
            }
            ImageView imageView = new ImageView(mContext);
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            GlideUtils.getInstance().loadCircleImage(mContext, CommonUtil.getImageUrl(item.getFinishStudents().get(i).getHeadPhoto()), imageView);
            imageView.setLayoutParams(mImageParams);
            imagesLL.addView(imageView);
        }
    }
}
